﻿#include "InstructionTurnTablePositionMode.h"

__SCRIPTINSTRUCTION_REGISTER(InstructionTurnTablePositionMode,ScriptInstruction::Instruction_TurnTable_PositionMode,&InstructionTurnTablePositionMode::fromByteArray1);

InstructionTurnTablePositionMode::InstructionTurnTablePositionMode()
{
  instructionFlag = Instruction_TurnTable_PositionMode;
}

InstructionTurnTablePositionMode::InstructionTurnTablePositionMode(InstructionTurnTablePositionMode const& instructionTurnTablePositionMode)
{
  *this=instructionTurnTablePositionMode;
}

InstructionTurnTablePositionMode& InstructionTurnTablePositionMode::operator=(InstructionTurnTablePositionMode const & instructionTurnTablePositionMode)
{
  *(ScriptInstruction*)this=instructionTurnTablePositionMode;
  position=instructionTurnTablePositionMode.position;
  rate=instructionTurnTablePositionMode.rate;
  acceleration=instructionTurnTablePositionMode.acceleration;
  return *this;
}

InstructionTurnTablePositionMode::~InstructionTurnTablePositionMode()
{}

QString InstructionTurnTablePositionMode::toString()
{
  return QStringLiteral("设置位置模式，位置：%1°，速率：%2°/s，加速度：%3°/s²")
      .arg(position,0,'f',4)
      .arg(rate,0,'f',4)
      .arg(acceleration,0,'f',4);
}

QByteArray InstructionTurnTablePositionMode::toByteArray()
{
  return QByteArray().append((char*)&position,sizeof (position))
      .append((char*)&rate,sizeof (rate))
      .append((char*)&acceleration,sizeof (acceleration));
}

InstructionTurnTablePositionMode* InstructionTurnTablePositionMode::clone()
{
  return new InstructionTurnTablePositionMode(*this);
}

ScriptInstruction* InstructionTurnTablePositionMode::fromByteArray1(char * const src,int size,int * offset)
{
  if((size-*offset)<byteArraySize)
    {
      return Q_NULLPTR;
    }
  InstructionTurnTablePositionMode* instructionTurnTablePositionMode=new InstructionTurnTablePositionMode();
  instructionTurnTablePositionMode->position=*(float*)(src+*offset);
  *offset+=sizeof (position);
  instructionTurnTablePositionMode->rate=*(float*)(src+*offset);
  *offset+=sizeof (rate);
  instructionTurnTablePositionMode->acceleration=*(float*)(src+*offset);
  *offset+=sizeof (acceleration);
  return instructionTurnTablePositionMode;
}
float InstructionTurnTablePositionMode::getPosition()
{
  return position;
}

InstructionTurnTablePositionMode* InstructionTurnTablePositionMode::setPosition(float position)
{
  this->position=position;
  return this;
}

float InstructionTurnTablePositionMode::getRate()
{
  return rate;
}

InstructionTurnTablePositionMode* InstructionTurnTablePositionMode::setRate(float rate)
{
  this->rate=rate;
  return this;
}

float InstructionTurnTablePositionMode::getAcceleration()
{
  return acceleration;
}

InstructionTurnTablePositionMode* InstructionTurnTablePositionMode::setAcceleration(float acceleration)
{
  this->acceleration=acceleration;
  return this;
}
